# -*- coding:utf-8 -*-
"""
describe：tools
Author：winni
Email：mwn666888@163.com
Time: 2024/11/29 14:00
Software: PyCharm
"""
# 导入os包
import os
import datetime
import os.path
from common.ReadYaml import ReadYaml


def 返回当前时间年_月_日加N天的时间戳(增加天数:int):
        return int((datetime.datetime.now() + datetime.timedelta(days=增加天数)).timestamp())

def 目标接口地址(接口源: str, 目标地址: str):
    path = ReadYaml(os.path.join(get_path("/data/接口地址.yaml")),part=f"{接口源}").read()[0][f"{目标地址}"]
    if path[0] != "/":
        path = path + "/"
    return path

def get_path(path: str = None):
    root_path = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
    if path:
        if "/" in path:
            path = path.split("/")
        elif "\\" in path:
            path = path.split("\\")
        else:
            path = [path]
        return os.path.join(root_path, *path)
    else:
        return root_path

def 获取账号密码(账号名: str, 环境: str):
    账号密码对 = [ReadYaml(get_path("/data/账号.yaml"), part=f"{环境}").read()[0][f"{账号名}"],
                  ReadYaml(get_path("/data/账号.yaml"), part=f"{环境}").read()[0][f"{账号名}密码"]]
    # print(账号密码对)
    return 账号密码对

# def get_project_path():
#     """
#     获取项目目录
#     :return:
#     """
#     # api_auto_test为项目名称，可以自行调整
#     project_name = "nmb_auto_api_test"
#     # 获取当前项目路径
#     file_path = os.path.dirname(__file__)
#     # 因为file_path返回的是当前文件所在位置的目录，而我们需要项目的跟目录
#     # 所以这里使用切片，把返回的路径切片到刚好为根目录的地方（方法不唯一）
#     a = file_path[:file_path.find(project_name) + len(project_name)]
#     return a
#
#
# def sep(path, add_sep_before=False, add_sep_after=False):
#     """
#     拼接文件路径，添加系统分隔符
#     :param path: 路径列表，类型为数组  ["config","environment.yaml"]
#     :param add_sep_before: 是否需要在拼接的路径前加一个分隔符
#     :param add_sep_after: 是否需要再拼接的路径后加一个分隔符
#     :return:
#     """
#     # 拼接传入的数组
#     all_path = os.sep.join(path)
#     # 如果before为TRUE，那就在路径前面加“/”
#     if add_sep_before:
#         all_path = os.sep + all_path
#     # 如果after为TRUE，那就在路径后面加“/”
#     if add_sep_after:
#         all_path = all_path + os.sep
#     return all_path

if __name__ == '__main__':
    # 测试一下
    # print(get_project_path())
    # print(sep(["config", "environment.yaml"], add_sep_before=True))
    print(int((datetime.datetime.now()+ datetime.timedelta(days=3)).timestamp()))
    print(返回当前时间年_月_日加N天的时间戳(3))
    result = get_path('.auth')
    print(result)
    result = ReadYaml(get_path("/data/账号.yaml"),part=f"playwright").read()[0][f"测试员账号密码"]
    result = 获取账号密码("测试员账号", "playwright0")
    result = 目标接口地址("项目集", "删除项目集接口")
    print(result)

